<?php

namespace app\agent\controller;

use controller\BasicAgent;
use service\LogService;
use think\App;
use think\Db;

/**
 * 后台参数配置控制器
 * Class Config
 * @package app\admin\controller
 */
class Finance extends BasicAgent
{
    public function __construct( App $app = null )
    {
        parent::__construct($app);
        //进行匹配

    }


    //执行资金变动记录汇总的操作
    public function index()
    {
        $this->title = '资金明细';
        $get = $this->request->get();
        $db = Db::name("bags_log");
        $where = array();

        if($this->user['id'] != 10000) {
            if (strlen($this->shopUnderUsers) > 0 || empty($this->shopUnderUsers)) {
                $db->where('uid', 'in', $this->shopUnderUsers);
            }
        }
        if (isset($get['orderid']) && $get['orderid'] != '') {
            $where['orderid'] = $get['orderid'];
            $db->where($where);
        }

        if (isset($get['member_id']) && $get['member_id'] != '') {
            $where['uid'] = $get['member_id'] ;
            $db->where($where);
        }

        if (isset($get['type']) && $get['type'] != '') {
            $where['type'] = $get['type'];
            $db->where($where);
        }

        if (isset($get['extends']) && $get['extends'] != '') {
            $where['extends'] = $get['extends'];
            $db->where($where);
        }
        if (isset($get['date']) && $get['date'] != '') {
            $date = $get['date'];
            list($start, $end) = explode(' - ', $date);
            $db->where('create_time', 'between', [strtotime($start), strtotime($end)]);
        }
        if (isset($get['field']) && $get['field'] != '') {
            if ($get['field'] == 'phone') {
                $get['name'] && $where['uid'] = Db::name('store_member')->where(array('phone' => $get['name']))->value('id');
            } elseif($get['field'] == 'username') {
                $get['name'] && $where['uid'] = Db::name('store_member')->where(array('nickname' => $get['name']))->value('id');
            }else{
                $where[$get['field']] = $get['name'];
            }

            $db->where($where);
        }
        $db->order('create_time desc,id desc');
        return parent::_list($db);
    }

}